﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Kenly.ChineseSegment.Core
{
    /// <summary>
    /// 统计分词比较器。
    /// </summary>
    public class SegmentCountComparer:IComparer<SegmentCountPair>
    {
        private bool _ascend = true;


        public SegmentCountComparer()
        {
        }

        public SegmentCountComparer(bool ascend)
        {
            _ascend = ascend;
        }

        #region IComparer<SegmentCountPair> 成员

        public int Compare(SegmentCountPair x, SegmentCountPair y)
        {
            //若次数相同，按默认顺序排序。
            if (x.Count == y.Count)
            {
                return x.DefaultIndex - y.DefaultIndex;
            }
            return _ascend ? (x.Count - y.Count): (y.Count - x.Count);
        }

        #endregion

       
    }
}
